package com.wwtech.epp.ui.adapter.main;

import android.content.Intent;
import android.support.annotation.Nullable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.wwtech.epp.R;
import com.wwtech.epp.entity.WorkCategory;
import com.wwtech.epp.ui.activity.work.ApproveCenterActivity;
import com.wwtech.epp.ui.activity.work.DynamicAppActivity;
import com.wwtech.epp.ui.activity.work.ProductManageActivity;
import com.wwtech.epp.ui.activity.work.ProjectReportActivity;
import com.wwtech.epp.ui.activity.work.PunchCardActivity;
import com.wwtech.epp.ui.activity.work.TaskManageActivity;

import java.util.List;

/**
 * 作者：Android on 2017/8/28
 * 邮箱：365941593@qq.com
 * 描述：
 */

public class WorkCategoryAdapter extends BaseQuickAdapter<WorkCategory.DataBean, BaseViewHolder> {

    public WorkCategoryAdapter( @Nullable List<WorkCategory.DataBean> data) {
        super(R.layout.item_work_category, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, WorkCategory.DataBean dataBean) {
        helper.setText(R.id.name, dataBean.getCatName());
        RecyclerView recycerView = helper.getView(R.id.recycerView);
        GridLayoutManager gridLayoutManager = new GridLayoutManager(mContext, 4);
        recycerView.setLayoutManager(gridLayoutManager);
        WorkCategoryItemAdapter workCategoryItemAdapter = new WorkCategoryItemAdapter(dataBean.getApps());
        recycerView.setAdapter(workCategoryItemAdapter);
        workCategoryItemAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter baseQuickAdapter, View view, int i) {
                handlerClick(workCategoryItemAdapter.getData().get(i));
            }
        });
    }

    private void handlerClick(WorkCategory.DataBean.AppsBean item) {   //apptype == 0,就是本地应用，
        if (item.getAppType() == 0) {
            if (item.getAppId() == 1) {
                Intent intent = new Intent(mContext, PunchCardActivity.class);
                intent.putExtra("title", item.getAppName());
                mContext.startActivity(intent);
            } else if (item.getAppId() == 2) {
                Intent intent = new Intent(mContext, ProductManageActivity.class);
                intent.putExtra("title", item.getAppName());
                mContext.startActivity(intent);
            } else if (item.getAppId() == 3) {
                Intent intent = new Intent(mContext, ApproveCenterActivity.class);
                intent.putExtra("title", item.getAppName());
                mContext.startActivity(intent);
            } else if (item.getAppId() == 4) {
                Intent intent = new Intent(mContext, TaskManageActivity.class);
                intent.putExtra("title", item.getAppName());
                mContext.startActivity(intent);
            } else if(item.getAppId() == 5) {
                Intent intent = new Intent(mContext, ProjectReportActivity.class);
                intent.putExtra("title", item.getAppName());
                mContext.startActivity(intent);
            }
        } else if (item.getAppType() == 1) {
            Intent dynamicIntent = new Intent(mContext, DynamicAppActivity.class);
            dynamicIntent.putExtra("dataId", item.getAppId() + "");
            dynamicIntent.putExtra("title", item.getAppName());
            dynamicIntent.putExtra("dynamicUI", item.getAppUi());
            mContext.startActivity(dynamicIntent);
        } else {

        }
    }
}
